package com.example.music.Utils;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.SeekBar;

public class MusicSeekBar extends androidx.appcompat.widget.AppCompatSeekBar {

    public interface OnSeekBarChangeListener {
        void onProgressChanged(MusicSeekBar seekBar, int progress, boolean fromUser);
        void onStartTrackingTouch(MusicSeekBar seekBar);
        void onStopTrackingTouch(MusicSeekBar seekBar);

        void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser);

        void onStartTrackingTouch(SeekBar seekBar);

        void onStopTrackingTouch(SeekBar seekBar);
    }

    private OnSeekBarChangeListener listener;

    public MusicSeekBar(Context context) {
        super(context);
        init();
    }

    public MusicSeekBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MusicSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(MusicSeekBar seekBar, int progress, boolean fromUser) {

            }

            @Override
            public void onStartTrackingTouch(MusicSeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(MusicSeekBar seekBar) {

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                if (listener != null) {
                    listener.onProgressChanged(MusicSeekBar.this, progress, fromUser);
                }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                if (listener != null) {
                    listener.onStartTrackingTouch(MusicSeekBar.this);
                }
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                if (listener != null) {
                    listener.onStopTrackingTouch(MusicSeekBar.this);
                }
            }
        });
    }

    public void setOnSeekBarChangeListener(OnSeekBarChangeListener listener) {
        this.listener = listener;
    }
}
